package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product")
@CrossOrigin
public class BaseManageController {

    @Autowired
    ManageService manageService;

    @GetMapping("getCategory1")
    public Result getCategory1() {
        return Result.ok(manageService.getBaseCategory1());
    }
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id) {
        return Result.ok(manageService.getBaseCategory2(category1Id));
    }
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id) {
        return Result.ok(manageService.getBaseCategory3(category2Id));
    }
    @GetMapping("getBaseAttrInfo/{category1Id}/{category2Id}/{category3Id}")
    public Result  getBaseAttrInfo(@PathVariable Long category1Id,@PathVariable Long category2Id,@PathVariable Long category3Id) {
        return Result.ok(manageService.getBaseAttrInfo(category1Id,category2Id,category3Id));
    }
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    @GetMapping("getAttrInfo/{attrId}")
    public Result getAttrInfo(@PathVariable Long attrId){
        List<BaseAttrValue> baseAttrValues=manageService.getAttrInfo(attrId);
        return Result.ok(baseAttrValues);
    }
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
      BaseAttrInfo baseAttrInfo = manageService.getBaseAttr(attrId);
      if(baseAttrInfo!=null){
       return Result.ok(baseAttrInfo.getAttrValueList()) ;
      }
      return  Result.ok();
    }


}
